#ifndef QDEVICEDATAVIEW_H
#define QDEVICEDATAVIEW_H

#include "../../libs/device/qbasedefine.h"
#include "../../libs/core/qbaseitemdelegate.h"

#include <QTreeWidget>

class QDeviceManager;
struct tagDeviceInfo;
class QServerDataSync;
class QAbstractDataOperator;
class QDeviceDataView;

class QDeviceDataDelegate: public QBaseItemDelegate
{
public :
    QDeviceDataDelegate(QDeviceDataView* view):m_view(view){}
    QWidget* createEditor(QWidget *parent, const QStyleOptionViewItem &option, const QModelIndex &index) const;
    void setEditorData(QWidget *editor, const QModelIndex &index) const;
    void setModelData(QWidget *editor, QAbstractItemModel *model, const QModelIndex &index) const;
protected:
    QDeviceDataView *m_view;
};

class QDeviceDataView : public QTreeWidget
{
    Q_OBJECT
public:
    explicit QDeviceDataView(tagDeviceInfo* info,QWidget *parent = 0);
    ~QDeviceDataView();
    void clear();
signals:
protected:
    friend class QDeviceDataDelegate;

    void    mousePressEvent(QMouseEvent *event);
    void    drawRow(QPainter *painter, const QStyleOptionViewItem &options, const QModelIndex &index) const;


    void    contextMenuEvent(QContextMenuEvent *);
protected slots:
    void    data_refresh(const QString &uuid);
    void    data_value_refresh(const QStringList &list);
    void    lock();
protected:
    QMap<QString,QTreeWidgetItem*>  m_group_to_item;
    QMap<QString,QTreeWidgetItem*>  m_data_to_item;
    QMap<QTreeWidgetItem*,QString>  m_item_to_data;
    QMap<QString,QAbstractDataOperator*>    m_data_to_operator;
    QDeviceManager  *m_device_manager;
    QServerDataSync *m_data_sync;
    tagDeviceInfo   m_device_info;
};

#endif // QDEVICEDATAVIEW_H
